package com.soooft.tickey.po;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.social.security.SocialUser;
import org.springframework.social.security.SocialUserDetails;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Collection;
import java.util.Date;

/**
 * @Description
 * @author: Fanxl
 * @Date: Created in 2018/04/24 11:33
 */
@Table(name = "ts_user")
@Data
public class User implements SocialUserDetails {

    @Id
    @GeneratedValue(generator = "JDBC")
    private Long id;

    private String loginName;

    private String name;

    private String email;

    private String passowrd;

    private String unionId;

    private String openId;

    private String photo;

    private Date createTime;

    private Date updateTime;

    private String nickName;

    @Override
    public String getUserId() {
        return getId() + "";
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return AuthorityUtils.commaSeparatedStringToAuthorityList("admin");
    }

    @Override
    public String getPassword() {
        return passowrd;
    }

    @Override
    public String getUsername() {
        return loginName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
